package com.hrm.houfei.biz.impl;

import java.util.Date;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;

import com.hrm.houfei.biz.IEngageinforeleaseBiz;
import com.hrm.houfei.dao.IEngageinforeleaseDAO;
import com.hrm.houfei.po.Engageinforelease;

/**
 * @title 招聘信息发布管理业务实现类
 * @author 侯非
 * @date 2009-04-18
 */
public class EngageinforeleaseBizImpl implements IEngageinforeleaseBiz {

	// 招聘信息发布管理业务接口(用来进行spring注入)
	private IEngageinforeleaseDAO ieildao = null;

	public void setIeildao(IEngageinforeleaseDAO ieildao) {
		this.ieildao = ieildao;
	}

	public EngageinforeleaseBizImpl() {
		super();
	}

	/**
	 * @title 招聘信息发布登记
	 * @param entity
	 * @return 登记成功返回true,否则返回false
	 */
	public boolean addEngageinforelease(Engageinforelease entity) {
		try {
			entity.setEirAddDate(new Date());
			entity.setEirState("未审核");
			this.ieildao.save(entity);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	/**
	 * 多条件分页模糊查询
	 * 
	 * @param title
	 *            标题
	 * @param start
	 *            索引
	 * @param limit
	 *            每页要显示的记录的条数
	 * @return 当前页的所有记录 List<Engageinforelease>
	 */
	public List<Engageinforelease> findByPage(String title, String start,
			String limit) {
		// 离线查询
		DetachedCriteria criteria = DetachedCriteria
				.forClass(Engageinforelease.class);
		// 如果条件标题不为空,那么将条件标题附加上
		if (!"".equals(title) && null != title) {
			criteria.add(Restrictions.like("eirTitle", title,
					MatchMode.ANYWHERE));
		}

		// 为分页参数设置默认值
		if ("".equals(start) || null == start) {
			start = "0";
		}
		if ("".equals(limit) || null == limit) {
			limit = "10";
		}

		// 调用dao获取查询后的数据
		List<Engageinforelease> list = this.ieildao.findAllByPageCondition(
				criteria, Integer.parseInt(start), Integer.parseInt(limit));

		return list;
	}

	/**
	 * 根据条件查询总记录的条数
	 * 
	 * @param title
	 *            标题
	 * @return
	 */
	public int getPageListCount(String title) {
		// 离线查询
		DetachedCriteria criteria = DetachedCriteria
				.forClass(Engageinforelease.class);
		// 如果条件标题不为空,那么将条件标题附加上
		if (!"".equals(title) && null != title) {
			criteria.add(Restrictions.like("eirTitle", title,
					MatchMode.ANYWHERE));
		}
		// 调用dao获取查询后的数据
		int listCount = this.ieildao.getPageListCount(criteria);
		return listCount;
	}

	/**
	 * 审核职位发布信息
	 * @param checkName 审核人
	 * @param checkMemo 审核意见
	 * @param pkid 要审核的职位发布信息id
	 * @return 成功返回true,否则返回false
	 */
	public boolean checkEngageinforelease(String checkName, String checkMemo,
			int pkid) {
		try {
			Engageinforelease eir = this.ieildao.findById(pkid);
			eir.setEirCheckDate(new Date());
			eir.setEirMemo(checkMemo);
			eir.setUserCheckName(checkName);
			eir.setEirState("通过审核");
			this.ieildao.update(eir);
			return true;
		} catch (Exception e) {
			return false;
		}

	}

}
